package test.vo;

import java.util.List;

import javax.swing.table.AbstractTableModel;

public class DbTableColumns extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	public static final String[] nameCN = { "", "列名", "类型", "描述" };
	public static final int[] colWidth = { 20, 200, 100, 200 };
	private List<String[]> data;

	public DbTableColumns() {
	}

	public DbTableColumns(List<Columns> list) {
		this.data = list.stream().map(c -> {
			return new String[] { String.valueOf(c.getColumnId()), c.getColumnName(), c.getDataType(),
					c.getComments() };
		}).toList();
	}

	public List<String[]> getData() {
		return data;
	}

	public void setData(List<String[]> data) {
		this.data = data;
	}

	@Override
	public int getRowCount() {
		return null == data ? 0 : data.size();
	}

	@Override
	public int getColumnCount() {
		return nameCN.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return null == data ? null : data.get(rowIndex)[columnIndex];
	}

	@Override
	public String getColumnName(int column) {
		return nameCN[column];
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return String.class;
	}

}
